package com.neusoft.neuiotms.dcam.fixed.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcam.common.model.Manufacturer;
import com.neusoft.neuiotms.dcam.fixed.model.enums.MaintenanceChangeStatus;

import lombok.Getter;
import lombok.Setter;

/**
 * 资产
 *
 * @author sunchf
 */
@Getter
@Setter
@Entity
@Table(name = "neuiot_fixed_maintenance_change")
@org.hibernate.annotations.Table(appliesTo = "neuiot_fixed_maintenance_change", comment = "固定资产维保变更表")
public class MaintenanceChange extends AbstractAuditModel {

    private static final long serialVersionUID = 1L;

    @Length(max = 255, message = "维保变更编号不能超过{max}位")
    @Column(length = 255, nullable = false, unique = true)
    @Comment("varchar(255) NOT NULL COMMENT '维保变更编号'")
    private String code;

    /** 维保变更资产 */
    @ManyToMany(targetEntity = Asset.class)
    @JoinTable(name = "ref_maintenance_change_asset", joinColumns = {
            @JoinColumn(name = "maintenance_change_id", referencedColumnName = "id") }, inverseJoinColumns = {
                    @JoinColumn(name = "asset_id", referencedColumnName = "id") })
    @LazyCollection(LazyCollectionOption.TRUE)
    List<Asset> assets;

    /** 供应商 */
    @ManyToOne
    private Manufacturer manufacturer;

    /** 维保 */
    @OneToOne(cascade = CascadeType.ALL)
    private Maintenance maintenance;

    @Enumerated(EnumType.STRING)
    @NotNull(message = "维保变更状态不能为空")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) COMMENT '维保变更状态'")
    private MaintenanceChangeStatus changeStatus = MaintenanceChangeStatus.created;

}
